{extend name="public/layout" /}
{block name="main"}
    <div class="layui-container">
        <div class="layui-row">
            {foreach $modular as $value}
            <div style="width: 128px;float: left;margin-top: 30px;margin-left: 10px">
                <div class="layui-col-xs12">
                    {if isset($value['img'])&&$value['img']}
                    <img src="{$value['img']}" width="128">
                    {else}
                    <img src="{:getStrToFilePath('static/home/img/error.png')}" width="128">
                    {/if}
                </div>
                <div class="text-align-center">项目名称：{$value['name']}</div>
                <div class="text-align-center">项目模块：{$value['dir']}</div>
                <div class="text-align-center">项目作者：{$value['author']}</div>
                <div class="text-align-center">
                    {if isset($value['install'])&&$value['install']=='1'}
                    <a class="layui-btn layui-btn-sm layui-btn-normal" href="{:url('admin/index/signin?modular='.$value['dir'])}">进入</a>
                    {else}
                    <button class="layui-btn layui-btn-sm layui-btn-danger anzhuang" data-model="{$value['dir']}">安装</button>
                    {/if}
                </div>
            </div>
            {/foreach}
            <div style="width: 128px;float: left;margin-top: 30px;margin-left: 30px">
                <img onclick="tianjia()" style="cursor: pointer" src="{:config('webroot')}/static/home/img/jiahao.jpg" width="128"/>
            </div>
        </div>
    </div>
{/block}
{block name="javascript"}
<script>
    $(".anzhuang").click(function () {
        var modular = $(this).attr('data-model');
        layer.confirm('确定安装吗？',{
            btn:['确定','取消']
        },function () {
            var index = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
            $.post("{:url('api/install')}",{modular:modular},function (res) {
                layer.close(index);
                console.log(res);
                if(res.code==200){
                    layer.msg(res.msg)
                    setTimeout(function () {
                        window.location.reload();
                    },1000);
                }else{
                    layer.msg(res.msg);
                }
            })
        })
    })
    function tianjia() {
        layer.open({
            type: 2,
            title: '添加项目',
            shadeClose: true,
            shade: 0.8,
            area: ['500px', '90%'],
            content:"{:url('index/add')}" ,//iframe的url,
            end:function () {
                window.location.reload();
            }
        });
    }
</script>
{/block}